local UIBase = require("view.UIBase")
local ChatMiniCell = class("ChatMiniCell", UIBase)
local Vector2 = require("utils.Vector2")
local Vector3 = require("utils.Vector3")

local NORMAL_CELL_HEIGHT = 30

function ChatMiniCell:ctor(parent, msg)
    self._chatMsg = msg
    local resource = {
        path = "Prefabs/View/Chat",
        name = "ChatMiniCell",
        parent = parent
    }
    ChatMiniCell.super.ctor(self, resource)
end

function ChatMiniCell:awake()
    local name = self._chatMsg:getName()
    local content = self._chatMsg:getContent()
    self._textContent.text = Lang.get("lang_chat_mini_msg", {name = name, msg = content})
    local preferHeight = self._textContent.preferredHeight
    if preferHeight > NORMAL_CELL_HEIGHT then
        local oldSize = self._panel.sizeDelta
        self._panel.sizeDelta = Vector2.new(oldSize.x, preferHeight + 1)
        local offset = preferHeight - NORMAL_CELL_HEIGHT + 1
        local pos = self._textContent.rectTransform.anchoredPosition
        pos.y = pos.y + offset
        self._textContent.rectTransform.anchoredPosition = pos
    end
end

function ChatMiniCell:getPanel()
    return self._panel
end

return ChatMiniCell
